#include <stdio.h>
#include <stdlib.h>
#include<Allegro.h>
#define GFX_W 800
#define GFX_H 600
#define NB_IMAGES 4

struct somajam {
    BITMAP * img_right[NB_IMAGES];
    BITMAP * img_left[NB_IMAGES];
    int x, y;
    int direction;// 0:right 1:left 2:up
};
    typedef struct somajam somajam;
struct alien
{
 BITMAP * img_right[NB_IMAGES];
    BITMAP * img_left[NB_IMAGES];
    int x, y;
    int direction;// 0:right 1:left
};
    typedef struct alien alien;

int main()
{
   char chemin_background[]="./images/background.bmp";

    BITMAP *Buffer;
    BITMAP *Background=NULL;
    BITMAP *BackgroundCol=NULL;
    alien alien;

    int compteur;
    void load_somajam(somajam *somajam)
{
    int i;
    char buf[50];
    for (i = 0; i < NB_IMAGES; i++) {
        sprintf(buf, "./images/right.bmp", i);
        somajam->img_right[i] = load_bitmap(buf, NULL);
        sprintf(buf, "./images/left.bmp", i);
        somajam->img_left[i] = load_bitmap(buf, NULL);
    }
}
void destroy_somajam(somajam*somajam)
{
    int i;
    for (i = 0; i < NB_IMAGES; i++) {
        destroy_bitmap(somajam->img_right[i]);
        destroy_bitmap(somajam->img_left[i]);
    }

}
void init_somajam(somajam *somajam)
{
    somajam->direction = 0;
    somajam->x = SCREEN_W / 2;
    somajam->y = SCREEN_H / 2;
}
void move_somajam_right(somajam *somajam,int *compteur,BITMAP * Background)
{

    if (key[KEY_RIGHT] && (somajam->x < SCREEN_W - somajam->img_right[0]->w)) {
        *compteur+=1;

        (somajam->x)+=1;
        somajam->direction = 0; //right
    }

}

void move_somajam_left(somajam *somajam,int *compteur,BITMAP * Background)
{

    if (key[KEY_LEFT] && (somajam->x > 0 + somajam->img_left[0]->w)) {
        *compteur+=1;

        (somajam->x)-=1;
        somajam->direction = 1; //left
    }
}
void jump_somajam(somajam *somajam,BITMAP * Background)
{

    if (key[KEY_UP] && (somajam->y > 0) ) {
        (somajam->y)-=5;
        somajam->direction = 2; //jump
    }

}

    return 0;
}
